<?php
RCoreImporter::cls("html.AbstractHtmlCombobox" );

class MultipleHtmlCombobox extends AbstractHtmlCombobox {
	
	function setValue($valueOrArrayContain) {
		$this->_selectedValue = $valueOrArrayContain;
		return true;
	}
	
	/**
	 * Create HTML text for the combobox
	 *
	 * @param string $emptyText the text for empty value. if this equal to null then there isn't any blank value in combobox
	 * @param string $cssCls
	 * @param string $style
	 * @param string $id
	 * @param string $extAttributes
	 * @return string
	 */
	function createCombobox($emptyText = "- - Select Filter - -", $cssCls = null, $style = null, $id = null, $extAttributes = "") {
		if ($emptyText !== null) {
			$fields [""] = $emptyText;
		}
		
		$vars = get_object_vars ( $this );
		foreach ( $vars as $key => $value ) {
			if ('_' == substr ( $key, 0, 1 )) {
				continue;
			}
			$fields [$key] = $value;
		}
		
		RCoreImporter::cls("helper.RHtmlHelper" );
		return MultipleHtmlCombobox::createSelectHtml ( $this->_cbxName, $fields, $this->_selectedValue, $extAttributes, $id, $cssCls, $style );
	}
	
	/**
	 * Create the HTML select box (combobox)
	 *
	 * @param string $name name of combobox
	 * @param array $arrayValue array content the value and View Name. it must be in define: ($value=>$viewName)
	 * @param string $selectedValue the selected value
	 * @param string $extAttributes more attributes string for this component
	 * @param string $htmlId the id of this HTML. by default it will be equal to the $name
	 * @param string $cssCls the CSS class of this control
	 * @param string $style the style string if this control
	 * 
	 * @return string The return HTML
	 */
	function createSelectHtml($name, $arrayValue, $arrayOrObject = "", $extAttributes = "", $htmlId = "", $cssCls = "", $style = "") {
		if (empty ( $htmlId )) {
			$htmlId = $name;
		}
		//		$selectedValue = RubikHelper::getValueFrom($arrayOrObject, $name); 
		if (! empty ( $cssCls )) {
			$extAttributes .= "class=\"$cssCls\" ";
		}
		if (! empty ( $style )) {
			$extAttributes .= "style=\"$style\" ";
		}
		
		$result = "<select name=\"$name\" id=\"$htmlId\" $extAttributes >\n";
		foreach ( $arrayValue as $value => $viewName ) {
			if (in_array ( $value, $arrayOrObject )) {
				$result .= "\t<option value=\"$value\" selected=\"true\">$viewName</option>\n";
			} else {
				$result .= "\t<option value=\"$value\">$viewName</option>\n";
			}
		}
		$result .= "</select>";
		return $result;
	}
}
?>